$().ready(function() {

});
function countdown(){
	html="";

	html+='<div class="wrapper-dates">';
		html+='<div class="left-side">';
			html+='<span>Months</span>';
			html+='<div class="clearfix"></div>';
				html+='<div class="number-date-left">';
					html+='<div class="tmonths"></div>';
				html+='</div>';
			html+='</div>';
			html+='<div class="right-side">';
				html+='<span>Days</span>';
				html+='<div class="clearfix"></div>';
				html+='<div class="number-date-right">';
					html+='<div class="tdays"></div>';
				html+='</div>';
			html+='</div>';	
		html+='</div>';
		html+='<div class="wrapper-countdown-label">';
			html+='<span>.. until your baby arrives</span>';
		html+='</div>';
	html+='</div>';
	$('.box-two-content').html(html);
	get_date();
	$('.box-two .title span').text("Countdown");
	switchwindow("countdown");
}
function countdown_nav(){
	var chk_log = $.cookie('chk_log');	
	if(chk_log==1){	
		html="";

		html+='<div class="wrapper-dates">';
			html+='<div class="left-side">';
				html+='<span>Months</span>';
				html+='<div class="clearfix"></div>';
					html+='<div class="number-date-left">';
						html+='<div class="tmonths"></div>';
					html+='</div>';
				html+='</div>';
				html+='<div class="right-side">';
					html+='<span>Days</span>';
					html+='<div class="clearfix"></div>';
					html+='<div class="number-date-right">';
						html+='<div class="tdays"></div>';
					html+='</div>';
				html+='</div>';	
			html+='</div>';
			html+='<div class="wrapper-countdown-label">';
				html+='<span>.. until your baby arrives</span>';
			html+='</div>';
		html+='</div>';
		$('.box-two-content').html(html);		
		$('.box-two .title span').text("Countdown");
		get_date();
		switchwindow_no_animate("countdown");
	}
}

function get_months_days(res){
	var ndays = 280;
	var dd = res.dd;
	var mm = res.mm;
	var yyyy = res.yyyy;		
	var dateConceptionDate = $.cookie('dateConceptionDate');
	cdate = dateConceptionDate.split('-');
	
	nmonths = ndays/30.4166666667;// get 9 months
	nConceptionDate = new Date(cdate[0], cdate[1]-1,cdate[2]);// get date of conception
	
	nConceptionDate.setMonth(nConceptionDate.getMonth()+nmonths);// get due date
	console.log(nConceptionDate)
	var days = Math.round((nConceptionDate-(new Date(yyyy, mm-1,dd)))/86400000); // now - due
	console.log(days);
	tmonths = days/30.4166666667;
	tdays = (tmonths%1)/0.0328767123288;
	
	tmonths = Math.floor(tmonths);
	tdays = Math.floor(tdays);
	
	$('.tmonths').html(tmonths);
	$('.tdays').html('&nbsp;&nbsp;'+tdays);		
}

function get_date(){
	xfunc = "countdown/get_date";
	data_sent = {};
	
	$.ajax({ 
		type: "POST", // request type POST
		url: base_url+xfunc, // post to PHP file
		data: data_sent, // request send to PHP file
		dataType:'json',
		success: function(result){ // result = return from php request		
			get_months_days(result);
		}
	});	
}